package com.hxf.web.action.coupons;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.hxf.common.DateUtil;
import com.hxf.common.GlobalMPURL;
import com.hxf.dto.CouponsDto;
import com.hxf.dto.MenuDto;
import com.hxf.dto.ReturnData;
import com.hxf.exception.DaoLevelException;
import com.hxf.exception.ServiceException;
import com.hxf.web.action.WebActionBase;

@Results({@Result(name = "success", location = "../common/success.jsp"), @Result(name = "error", location = "../common/error.jsp"), @Result(name = "msg", location = "../common/msg.jsp")})
public class CouponsAction extends WebActionBase{

	private static final long serialVersionUID = 1L;
	private CouponsDto couponsDto;
	private List<CouponsDto> listCouponseDto;
	private Integer id;
	private String name;
	private String couponsNo;
	private Double amount;
	private Integer numbers;
	private String beginDate;
	private String endDate;
	private String remark;
	private Integer couponsType;
	
	public String selectCoupons() throws ServiceException, DaoLevelException{
		
		ReturnData<CouponsDto> returnCoupons = super.serviceFacade.getCouponsService().findByCoupone(couponsDto, targetPage, pageSize);
		listCouponseDto = returnCoupons.getResultlist();
		this.setRecordCount(returnCoupons.getRecordcount());
		
		return "coupons-list";
	}
	
	public String addCoupone(){
		
		return "coupons-add";
	}
	
	public String saveCoupons(){
		try {

			CouponsDto coupons = new CouponsDto();
			coupons.setName(name);
			coupons.setAmount(amount);
			coupons.setCouponsNo(couponsNo);
			coupons.setBeginDate(beginDate);
			coupons.setEndDate(endDate);
			
			if (id == null) {
			
				super.serviceFacade.getCouponsService().save(coupons);//保存
			} else { 
				super.serviceFacade.getCouponsService().update(coupons);//修改			
			}
			requestURL = "menu!menuList.html";
		} catch (ServiceException e) {
			e.printStackTrace();
			logger.debug(e.getMessage(), e);
		}
		return SUCCESS;
	}

	public CouponsDto getCouponsDto() {
		return couponsDto;
	}

	public void setCouponsDto(CouponsDto couponsDto) {
		this.couponsDto = couponsDto;
	}

	public List<CouponsDto> getListCouponseDto() {
		return listCouponseDto;
	}

	public void setListCouponseDto(List<CouponsDto> listCouponseDto) {
		this.listCouponseDto = listCouponseDto;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCouponsNo() {
		return couponsNo;
	}

	public void setCouponsNo(String couponsNo) {
		this.couponsNo = couponsNo;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Integer getNumbers() {
		return numbers;
	}

	public void setNumbers(Integer numbers) {
		this.numbers = numbers;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Integer getCouponsType() {
		return couponsType;
	}

	public void setCouponsType(Integer couponsType) {
		this.couponsType = couponsType;
	}

	public String getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}
	
}
